package com.demo.applicationlistener;

import java.util.List;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.demo.livemanagement.livedelayqueue.LiveDelayInfo;
import com.demo.livemanagement.livedelayqueue.LiveDelayQueue;
import com.demo.livemanagement.service.LiveService;
import com.demo.utils.applicationcontext.SpringContextUtil;

//注册监听器
@Component
public class ApplicationReadyListener implements ApplicationListener<ApplicationReadyEvent> {

	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		System.err.println("------------应用程序准备就绪----------");
		LiveService bean1 = (LiveService) SpringContextUtil.getBean(LiveService.class);
		// LiveService bean2 = (LiveService)
		// FreshSpringContextUtil.getBean(LiveService.class);
//		System.out.println("bean1" + bean1);
		// System.out.println("bean2"+bean2);
		List<LiveDelayInfo> list = bean1.selectWaitForUpdateLiveDelay();
		// System.out.println("size:"+list.size());
		@SuppressWarnings("unchecked")
		LiveDelayQueue<LiveDelayInfo> qu = LiveDelayQueue.getInstance();
		qu.addAll(list);

	}

}
